/*
** b_env.c for mysh in /home/lingla_j/work/tutorat/env
** 
** Made by julien linglain
** Login   <lingla_j@epitech.net>
** 
** Started on  Tue Feb 28 23:06:10 2012 julien linglain
** Last update Thu Mar 22 16:11:15 2012 julien linglain
*/

#include <stdio.h>
#include <stdlib.h>
#include "mysh.h"

int	my_env(int ac, char *s, char **av, t_list *env)
{
  char	*pwd;

  pwd = get_current_dir_name();
  if (ac == 1 || check_space(av[1]) == 1)
    {
      my_add(env, "PWD", pwd);
      my_print(env);
    }
  else
    my_puterror("Usage: env.\n");
  free(pwd);
  return (EXIT_SUCCESS);
}

int	my_unsetenv(int ac, char *s, char **av, t_list *env)
{
  if (ac == 1)
    my_puterror("unsetenv: Too few arguments. Usage: unsetenv [key].\n");
  if (ac > 2)
    my_puterror("unsetenv: Too many arguments. Usage: unsetenv [key].\n");
  if (ac == 2)
    delete_node(env, av[1]);
  return (EXIT_SUCCESS);
}

int	my_setenv(int ac, char *s, char **av, t_list *env)
{
  if (ac == 1)
    my_print(env);
  if (ac == 2)
    my_add(env, av[1], NULL);
  if (ac > 3)
    my_puterror("setenv: Wrong arguments. Usage: setenv [key] [value].\n");
  if (ac == 3)
    my_add(env, av[1], av[2]);
  return (EXIT_SUCCESS);
}
